﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Resxus.DataAccess
{
    public class TableCollection : ICollection<ResourceTable>
    {
        public event Action<ResourceTable> AddRecordRepository;
        public event Action ClearRecordRepositories;
        public event Action<ResourceTable> RemoveRecordRepository;

        private List<ResourceTable> _RecordRepositories = new List<ResourceTable>();

        public ICollection<ResourceTable> Items
        {
            get
            {
                return this;
            }
        }

        #region ICollection<ResourceRecord> 멤버

        void ICollection<ResourceTable>.Add(ResourceTable item)
        {
            this._RecordRepositories.Add(item);

            if (this.AddRecordRepository != null)
            {
                this.AddRecordRepository(item);
            }
        }

        void ICollection<ResourceTable>.Clear()
        {
            this._RecordRepositories.Clear();

            if (this.ClearRecordRepositories != null)
            {
                this.ClearRecordRepositories();
            }
        }

        bool ICollection<ResourceTable>.Contains(ResourceTable item)
        {
            return this._RecordRepositories.Exists(param => { return param.Equals(item); });
        }

        void ICollection<ResourceTable>.CopyTo(ResourceTable[] array, int arrayIndex)
        {
            this._RecordRepositories.CopyTo(array, arrayIndex);
        }

        int ICollection<ResourceTable>.Count
        {
            get { return this._RecordRepositories.Count; }
        }

        bool ICollection<ResourceTable>.IsReadOnly
        {
            get { return false; }
        }

        bool ICollection<ResourceTable>.Remove(ResourceTable item)
        {
            bool result = this._RecordRepositories.Remove(item);

            //이벤트 
            if (this.RemoveRecordRepository != null)
            {
                this.RemoveRecordRepository(item);
            }

            return result;
        }

        #endregion

        #region IEnumerable<ResourceRecord> 멤버

        IEnumerator<ResourceTable> IEnumerable<ResourceTable>.GetEnumerator()
        {
            return this._RecordRepositories.GetEnumerator();
        }

        #endregion

        #region IEnumerable 멤버

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return this._RecordRepositories.GetEnumerator();
        }

        #endregion
    }
}
